<?php

class CMRPageTest extends CMRPage
{
protected function getContentsDiv()
	{
		$html = "<div id=\"content\">\n";
		$html .= "<h1>Test Page</h1>";

		$sectionsPanel = new SectionsPanel('');
		$html .= $sectionsPanel->getHTML();

		$shortcutPanel = new ShortcutPanel('');
		$html .= $shortcutPanel->getHTML();
		
//		$html .= $this->doRepertoireItems();
//		$html .= $this->doComposers();
		$html .= $this->emailMembers();
	}
	
	private function emailMembers()
	{
/*		$sql = "SELECT * FROM Users";
		$this->Database->ExecuteSQL($sql);
		$resources = array();
		while($row=$this->Database->getRow())
		{
			$details=array();
			if($row['Email']!="")
			{
				$details['LongName'] = $row['LongName'];
				$details['Email'] = $row['Email'];
				$details['Password'] = $row['Password'];

				
				$messageHTML = "<h1>COA Website - please ignore the previous message.</h1>";
				$messageHTML .= "<p>Dear ".$row['LongName'].",</p>";
				$messageHTML .= "<p>Apologies for the previous email which was sent in error.</p>";
				$messageHTML .= "<p>The CMR Website team</p>";
				
				
				$message = new Message();
				$message->addRecipient($row['Email']);
				$message->addRecipient('webmaster@cathedralmusicresources.org');
				$message->setSubject("COA Website - please ignore previous message");
				$message->setFrom("Cathedral Music Resources<webmaster@cathedralmusicresources.org>");
				$message->addStyle("p, {font-family: sans-serif;vertical-align:top;font-size: 70%;color:#003366;}");
				$message->addStyle("h1{font-family: sans-serif;font-size: 100%;color:#003366;}");
		
				$message->setMessageBody($messageHTML);
				$message->send();
				echo $messageHTML;
				
			}
		}

	*/	
	}
	
	private function doComposers()
	{
 // For Composers
  		$sql = "SELECT ResourceID from Resources WHERE ResourceTypeID=3";
		$this->Database->ExecuteSQL($sql);
		$resources = array();
		while($row=$this->Database->getRow())
		{
			$database=$this->Database->Recopy();
			$resource = new ResourceComposer($database,$row['ResourceID']);
			array_push($resources,$resource);
		}
		
		foreach ($resources as $resource) 
		{

			$firstnameandinitials = trim($resource->getFirstName().' '.$resource->getSecondNames());
			
			$title = $resource->getSurname().' ('.$firstnameandinitials.')';
			
			$description = 'Composer information for '.$resource->getFirstName();
			if($resource->getSecondNames()!="") $description .= ' '.$resource->getSecondNames();
			$description .= ' '.$resource->getSurname();
			
			$keywords =  $resource->getSurname();
						
			$html .= "<p>".$title."<br>".$description."<br>".$keywords."</p>";
			
			$sql="UPDATE Resources SET ResourceTitle='".$title."', ResourceDescription='".$description."', ResourceKeywords='".$keywords."' WHERE ResourceID='".$resource->getResourceID()."'";
			$html .= "<p>".$sql."</p>\n";
			$this->Database->ExecuteSQL($sql);
			
		}
	
		$html .= "</div>\n";
		return $html; 
	}


	private function doRepertoireItems()
	{
	//   For Repertoire items
		$sql = "SELECT ResourceID from Resources WHERE ResourceTypeID=2";
		$this->Database->ExecuteSQL($sql);
		$resources = array();
		while($row=$this->Database->getRow())
		{
			$database=$this->Database->Recopy();
			$resource = new ResourceRepertoireInfo($database,$row['ResourceID']);
			array_push($resources,$resource);
		}
		
		foreach ($resources as $resource) 
		{
			$composer = new ResourceComposer($this->Database->Recopy(),0);
			$composer->loadComposer($resource->getComposerID());
			
			$firstnameandinitials = trim($composer->getFirstName().' '.$composer->getSecondNames());
			
			$title = $composer->getSurname().' ('.$firstnameandinitials.') - '.$resource->getTitle();
			
			$description = 'Repertoire information for '.$resource->getTitle().' by '.$composer->getFirstName(). ' '.$composer->getSecondNames().' '.$composer->getSurname();
			
			$keywords =  $composer->getSurname().' '.$resource->getTitle();
			
			$html .= "<p>".$title."<br>".$description."<br>".$keywords."</p>";
			
			$sql="UPDATE Resources SET ResourceTitle='".$title."', ResourceDescription='".$description."', ResourceKeywords='".$keywords."' WHERE ResourceID='".$resource->getResourceID()."'";
			$html .= "<p>".$sql."</p>\n";
			$this->Database->ExecuteSQL($sql);
			
		}
	
		$html .= "</div>\n";
		return $html;
		
	}
}
				
